<!DOCTYPE html>
<html>
<head>
    <include file="public/public_css" />

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <include file="public/header-min" />
    <!-- Left side column. contains the logo and sidebar -->
    <include file="public/left" />
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                免费资源管理
                <a href="javascript:void(0);" onclick="addResources();"><button type="button" class="btn btn-primary">添加资源</button></a>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li class="active"> 免费资源管理管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Small boxes (Stat box) -->
            <!-- Small boxes (Stat box) -->
            <div class="row">
                <table id="menuList" class="table table-hover">
                    <tr>
                        <th style="text-align:center;">
                            <input id="all" type="checkbox" >
                        </th>
                        <th>id</th>
                        <th>名称</th>
                        <th>资源URL</th>
                        <th>添加时间</th>
                        <th>操作</th>
                    </tr>
                    <volist name="list" id="vo">
                        <tr>
                            <td>
                                <input type="checkbox"  name="id[]" value="{$vo.id}">
                            </td>

                            <td>{$vo.id}</td>
                            <td>{$vo.name}</td>
                            <td>{$vo.url}</td>
                            <td>{:date('Y-m-d H:i', $vo.add_time)}</td>
                            <td>
                                <a class="delResources" href="javascript:void(0);" >
                                    <input type="hidden" value="{$vo.id}">
                                    <button type="button" class="btn btn-danger">删除</button>
                                </a> |
                                <a class="editResources" href="javascript:void(0);">
                                    <input type="hidden" value="{$vo.id}">
                                    <button type="button" class="btn btn-info">修改</button>
                                </a>
                            </td>
                        </tr>
                    </volist>
                </table>

                <div>
                    <button type="button" class="btn btn-danger delResources" >删除</button>
                </div>
                <div>
                    {$list->render()}
                </div>
            </div>


        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <include file="public/footer" />

    <!-- Control Sidebar -->

    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<include file="public/public_js" />

<script>
    //添加友情链接
    function addResources(){
        layer.open({
            type: 2,
            area: ['750px', '550px'],
            fixed: false, //不固定
            maxmin: true,
            content: '{$Think.WEB_PATH}/Admin/Resources/addResources'
        });
    }
    //修改友情链接
    $('.editResources').click(function(){
        var id = $(this).children("input").val();
        layer.open({
            type: 2,
            area: ['900px', '650px'],
            fixed: false, //不固定
            maxmin: true,
            content:  '{$Think.WEB_PATH}/Admin/Resources/editResources?id='+id
        });
    });
    //删除友情链接
    $('.delResources').click(function(){

        //多选删除
        var checkId = [];
        ($('input[type=checkbox]:checked')).each(function(){
            checkId.push($(this).val());
        });
        //单个删除
        var id = $(this).children("input").val();
        layer.open({
            btn: ['删除', '取消'],
            yes: function(){
                //如果是多选
                if(checkId.length > 0){
                    id = checkId;
                }
                $.ajax({
                    type: 'POST', //GET,POST
                    url: '{$Think.WEB_PATH}/Admin/Resources/delResources?id=' + id,
                    dataType: 'json', //xml,json,script，默认为null
                    success: function (data) {
                        layer.open({
                            type: 1,
                            time: 5000,
                            area: ['200px', '200px'],
                            content: data.msg //服务器返回的消息
                        });
                        setTimeout(function () {
                            window.location.reload();
                        }, 1200);
                    },
                    error: function (event, errorText, errorType) { //错误时调用
                        alert(errorText + errorType);
                    }
                })

            },
            no: function(){

            },
            fixed: false, //不固定
            maxmin: true,
            content:'确定要删除吗？'
        });
    });

    //全选，全不选
    $('#all').click(function(){
        if(this.checked){
            $('input[type=checkbox]').prop("checked", true);
        }else{
            $('input[type=checkbox]').prop("checked", false);
        }
    });

</script>
</body>
</html>
